import axios from "axios";


let reqUrl;
const mode = import.meta.env.MODE;
if (mode === 'test') {
    reqUrl = '/'
} else if (mode === 'development') {
    reqUrl = 'http://localhost:10022'
} else {
    reqUrl = 'http://nucloud.cni23.com:23666'
}


const service = axios.create({
    // 超时 默认3分钟后超时
    timeout: 180000,
    baseURL: reqUrl
})

// request拦截器
service.interceptors.request.use(config => {
    // 是否需要设置 token
    const isToken = (config.headers || {}).isToken === false
    // 是否需要防止数据重复提交
    const isRepeatSubmit = (config.headers || {}).repeatSubmit === false
    // get请求映射params参数
    if (config.method === 'get' && config.params) {
        let url = config.url + '?' + tansParams(config.params);
        url = url.slice(0, -1);
        config.params = {};
        config.url = url;
    }
    return config
}, error => {
    console.log(error)
    Promise.reject(error)
})

// 响应拦截器
service.interceptors.response.use(res => {
        return  Promise.resolve(res.data)
    },
    error => {
        return Promise.reject(error)
    }
)

export default service;